package com.qingcheng.dao;

import com.qingcheng.pojo.order.ReturnOrder;
import com.qingcheng.vo.goods.ReturnOrderVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface ReturnOrderMapper extends Mapper<ReturnOrder> {

    @Select("SELECT ro.status,count(*) num FROM tb_return_order ro WHERE type = '1' GROUP BY status")
    List<Map> selectCountStatus();

    @Select("SELECT\n" +
            "\tro.*,\n" +
            "\trc.cause,\n" +
            "\to.receiver_contact,\n" +
            "\to.receiver_address,\n" +
            "\to.pay_money pay_money,\n" +
            "\tu.id uId,\n" +
            "\ta.id aId,\n" +
            "\ta.*\n" +
            "\n" +
            "FROM\n" +
            "\ttb_return_order ro\n" +
            "\tLEFT JOIN tb_return_cause rc ON ro.return_cause = rc.id\n" +
            "\tLEFT JOIN tb_return_order_item roi ON ro.id = roi.return_order_id\n" +
            "\tLEFT JOIN tb_order o ON roi.order_id = o.id\n" +
            "\tLEFT JOIN qingcheng_user.tb_user u ON u.id = ro.user_id\n" +
            "\tLEFT JOIN qingcheng_user.tb_address a ON u.username = a.username\n" +
            "\t\n" +
            "WHERE\n" +
            "\tro.order_id = #{orderId}")
    ReturnOrderVO findReturnOrder(String orderId);

    @Select("SELECT COUNT(*) FROM tb_return_order WHERE TYPE = #{status}")
    int findByStatus(@Param("status")String status);
}
